package org.hackystat.sdsa.analyzer.control.processor;

import java.util.Map;
import java.util.logging.Logger;

import org.hackystat.sdsa.analyzer.control.SensorDataUtil;
import org.hackystat.sdsa.analyzer.model.activity.Activity;
import org.hackystat.sdsa.analyzer.model.activity.BufferTransActivity;
import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData;

/**
 * Provides the BuffTransActivityProcessor.
 * 
 * @author hongbing
 *
 */
public class BuffTransActivityProcessor implements Processor {

  /**
   * Process the sensor data to get the BufferTrans activity.
   * 
   * @param sensorData Sensor data.
   * @param logger Service logger.
   * @return Buff trans activity.
   */
  public Activity process(SensorData sensorData, Logger logger) {
    return new BufferTransActivity(sensorData, logger);
  }

  /**
   * Checks whether the given sensor data is a type of buff trans activity.
   * 
   * @param sensorData Sensor data.
   * @return True if processable.
   */
  public boolean processable(SensorData sensorData) {
    String sensorDataType = sensorData.getSensorDataType();
    Map<String, String> propMap = SensorDataUtil.propMap(sensorData);
    
    if (!"DevEvent".equalsIgnoreCase(sensorDataType)) {
      return false;
    }
    
    if (!propMap.containsKey("type") || !"Edit".equalsIgnoreCase(propMap.get("type"))) {
      return false;
    }
    
    if (!propMap.containsKey("subtype") ||  
             !"BufferTransition".equalsIgnoreCase(propMap.get("subtype"))) {
       return false;     
    }
    
    return true;
  }

}
